<?php 
/**
*   控制器 基类
*/
class Controller extends Smarty
{
    function __construct()
    {
        // 对象链
        $this->setTemplateDir('./views')
               ->setCompileDir('./runtime/views_c')
               ->setCacheDir('./runtime/caches')
               ->setConfigDir('./configs');
        // 配置 模板变量的定界符
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = LEFT_R;
        // 配置 缓存控制 (开启缓存/缓存时间)
        $this->caching = CACHING;
        $this->cache_lifetime = CACHE_LIFETIME;
    }

    // 跳转和重定向
    public function redirect($message, $url = null)
    {
        echo "<script>alert('{$message}')</script>";
        if (empty($url)) {
            echo "<script>history.back()</script>";
        } else {
            echo "<script>location.href='{$url}'</script>";
        }
    }
    
    public function __call($fun, $params)
    {
        header("HTTP/1.0 404 not found");
        echo "<h1>404 Not Found - 控制器</h1>";
        exit;
    }
}